package com.example.imtoken.modules.main.wallet.details.trade.record

import com.blankj.utilcode.util.ClickUtils
import com.blankj.utilcode.util.TimeUtils
import com.chad.library.adapter.base.BaseQuickAdapter
import com.chad.library.adapter.base.module.LoadMoreModule
import com.chad.library.adapter.base.viewholder.BaseDataBindingHolder
import com.example.imtoken.R
import com.example.imtoken.databinding.ItemTransactionRecord1Binding
import com.example.imtoken.entitys.http.TransactionsEntityItem

class TransactionRecordAdapter(layoutResId: Int) :
    BaseQuickAdapter<TransactionsEntityItem, BaseDataBindingHolder<ItemTransactionRecord1Binding>>(
        layoutResId
    ), LoadMoreModule {
    override fun convert(
        holder: BaseDataBindingHolder<ItemTransactionRecord1Binding>,
        item: TransactionsEntityItem
    ) {

        ClickUtils.applyGlobalDebouncing(holder.itemView) {
            setOnItemClick(it, holder.adapterPosition)
        }

        holder.dataBinding?.item = item
        val time = item.block_at * 1000L
        holder.dataBinding?.tvCreateAt?.text =
            TimeUtils.millis2String(time)
        holder.dataBinding?.ivState?.run {
            if (item.is_contract) {
                setImageResource(R.mipmap.src_lib_eui_icon_contractfee)
            } else {
                if (item.status == 2) {
                    setImageResource(R.mipmap.src_lib_eui_icon_txfailednew)
                } else {
                    if (item.io == 1) {
                        setImageResource(R.mipmap.src_lib_eui_icon_txsend)
                    } else {
                        setImageResource(R.mipmap.src_lib_eui_icon_txreceive)
                    }
                }
            }
        }
    }
}